#include "mainwidget.h"
#include "ui_mainwidget.h"

#include <QDebug>

MainWidget::MainWidget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::MainWidget)
{
    ui->setupUi(this);

    systemWin = nullptr;
    qdWin = nullptr;
    dcsWin = nullptr;


    connect(&timer, &QTimer::timeout, this, &MainWidget::on_checkPlayLists);
    timer.setInterval(200);
    timer.setSingleShot(true);
    timer.start();


    qDebug() << "[MainWidget] \t Constructor";
}

MainWidget::~MainWidget()
{
    delete mDbopt;
    delete ui;
    qDebug() << "[MainWidget] \t Destructor";
}

void MainWidget::on_pushButtonDCS_clicked()
{

    dcsWin = new FormDCS(this);
    dcsWin->show();
}

void MainWidget::on_pushButtonQD_clicked()
{
    qdWin = new FormQD(this);
    qdWin->show();
}

void MainWidget::on_pushButtonSys_clicked()
{
    systemWin = new FormSystem(this);
    systemWin->show();
}

void MainWidget::on_checkPlayLists()
{
    QList<QString> playlists;
    mDbopt = new DCSDbOperator();

    if (mDbopt->getPlayLists(playlists))
    {
        if (playlists.size() > 0)
        {
            playWin = new FormPlay(this);
            playWin->show();
        }
    }
}
